#include "mainwindow.h"
#include "ui_mainwindow.h"
#include<QDebug>
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    // 1.创建菜单栏 (保持原始代码结构)
    QMenuBar* menubar = new QMenuBar();
    this->setMenuBar(menubar);  // 使用小写变量名

    // 2.创建菜单 (仅修正语法错误)
    QMenu* menu1 = new QMenu("文件");
    QMenu* menu2 = new QMenu("编辑");
    QMenu* menu3 = new QMenu("视图");
    menubar->addMenu(menu1);
    menubar->addMenu(menu2);
    menubar->addMenu(menu3);

    //3.给菜单添加菜单项
    QAction* action1 = new QAction("新建");
    QAction* action2 = new QAction("打开");
    QAction* action3 = new QAction("保存");
    menu1->addAction(action1);
    menu1->addAction(action2);
    menu1->addAction(action3);

    //4.给action添加信号槽
    connect(action1,&QAction::triggered,this,&MainWindow::handle);

}

MainWindow::~MainWindow()
{
    delete ui;
}
void MainWindow::handle()
{
    qDebug()<<"触发新建操作！";
}
